using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;

public class BarrierController : MonoBehaviour
{
    public float speed = 5f;
    private float repeatWidth;
    private Vector3 startPos;
    public int bindID;
    bool stop = false;
    
    // Start is called before the first frame update
    void Start()
    {
        repeatWidth = GetComponent<BoxCollider>().size.x / 2;
        startPos = transform.position;
       
    }

    // Update is called once per frame
    void Update()
    {
        stop = GameObject.Find("Player").GetComponent<PlayerController>().stop;
        if (!stop)
        {
            transform.Translate(Vector3.left * speed * Time.deltaTime);
        }
        
        if (bindID == 0)
        {
            if (transform.position.x < startPos.x - repeatWidth)
            {
                transform.position = startPos;
            }
        }
        else
        {
            if(this.transform.position.x < -8)
            {
                Destroy(this.gameObject);
            }
        }
    }


}
